﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="gridPresence.ascx.cs" Inherits="GUESTSMANAGEMENT.View.Report.gridPresence" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>

<ext:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</ext:ScriptManagerProxy>
<script type="text/javascript">
    var submitValue = function(grid, hiddenFormat, format) {
        hiddenFormat.setValue(format);
        grid.submitData(false);
    }

    var template = '<span style="color:{0};">{1}</span>';

    var change = function(value) {
        return String.format(template, (value > 0) ? 'green' : 'red', value);
    }

    var pctChange = function(value) {
        return String.format(template, (value > 0) ? 'green' : 'red', value + '%');
    }

    // this "setGroupStyle" function is called when the GroupingView is refreshed.     
    var setGroupStyle = function(view) {
        // get an instance of the Groups
        var groups = view.getGroups();

        for (var i = 0; i < groups.length; i++) {
            var spans = Ext.query("span", groups[i]);

            if (spans && spans.length > 0) {
                // Loop through the Groups, the do a query to find the <span> with our ColorCode
                // Get the "id" from the <span> and split on the "-", the second array item should be our ColorCode
                var color = "#" + spans[0].id.split("-")[1];

                // Set the "background-color" of the original Group node.
                Ext.get(groups[i]).setStyle("background-color", color);
            }
        }
    };
    
</script>
<ext:DesktopWindow ID="winGrdReportPresence" AutoHeight="true" Maximizable="false" ExpandOnShow="false" runat="server" Collapsible="true" Icon="User" Title="Relatório Analítico" Width="900" Height="400">
    <Body>
        <ext:Hidden ID="FormatType" runat="server" />
        <ext:Store ID="reportPresenceStore" OnSubmitData="Store1_Submit" runat="server" RefreshAfterSaving="Auto" GroupField="TMCONFIRM">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="NMUSER" />
                        <ext:RecordField Name="NMGUEST" />
                        <ext:RecordField Name="NMMAILGUEST" />
                        <ext:RecordField Name="CONFIRM" />
                        <ext:RecordField Name="TMCONFIRM" />
                        <ext:RecordField Name="FGTYPEINVITE" />
                        <ext:RecordField Name="NMEVENT" />
                        <ext:RecordField Name="DTEVENT" Type="Date" DateFormat="dd/mm/yyyy" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
            <SortInfo Field="TMCONFIRM" Direction="ASC" />
            <SortInfo Field="FGTYPEINVITE" Direction="ASC" />
        </ext:Store> 
        
        <ext:Store ID="userStore" runat="server" RefreshAfterSaving="auto">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="CDUSER" />
                        <ext:RecordField Name="IDUSER" />
                        <ext:RecordField Name="NMUSER" />
                        <ext:RecordField Name="FGUSER" />
                        <ext:RecordField Name="FGENABLED" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
               
       <ext:Panel ID="Panel1" runat="server" Width="890" Height="470">
            <Body>
                <ext:BorderLayout ID="BorderLayout1" runat="server">
                    <North>
                        <ext:FormPanel Width="800" Height="60" ID="FormPanel2" runat="server" Title="Dados do Evento" BodyStyle="padding:5px;" ButtonAlign="Right">
                            <Body>
                                <ext:ColumnLayout ID="ColumnLayout1" runat="server">
                                    <ext:LayoutColumn ColumnWidth=".3">
                                        <ext:Panel ID="LayoutColumn1" runat="server" Border="false">
                                            <Body>
                                                <ext:FormLayout ID="FormLayout2" runat="server">
                                                    <ext:Anchor>
                                                        <ext:DateField ID="eventDate" FieldLabel="Data" runat="server" AllowBlank="false" Width="100" BlankText="Data é requerido!" >
                                                            <AjaxEvents>
                                                                <Select OnEvent="EnventDateSelected" />
                                                            </AjaxEvents>
                                                        </ext:DateField>
                                                    </ext:Anchor>    
                                                </ext:FormLayout>
                                            </Body>
                                        </ext:Panel>
                                    </ext:LayoutColumn>
                                    <ext:LayoutColumn ColumnWidth=".3">
                                        <ext:Panel ID="LayoutColumn3" runat="server" Border="false">
                                            <Body>
                                                <ext:FormLayout ID="FormLayout5" runat="server">
                                                    <ext:Anchor>
                                                        <ext:ComboBox ID="comboUser" Disabled="true" FieldLabel="Usuário" ValueField="CDUSER" DisplayField="NMUSER" StoreID="userStore" runat="server" AllowBlank="true" Width="150">
                                                            <AjaxEvents>
                                                                <Select OnEvent="UserSelected" />
                                                            </AjaxEvents>
                                                            <Items>
                                                                <ext:ListItem Text="Todos" Value="-1"/>
                                                            </Items>
                                                        </ext:ComboBox>
                                                    </ext:Anchor>    
                                                </ext:FormLayout>
                                            </Body>
                                        </ext:Panel>
                                    </ext:LayoutColumn>
                                    <ext:LayoutColumn ColumnWidth=".3">
                                        <ext:Panel ID="LayoutColumn2" runat="server" Border="false">
                                            <Body>
                                                <ext:FormLayout ID="FormLayout3" runat="server">
                                                    <ext:Anchor>
                                                        <ext:TextField Width="150" ID="eventName" ReadOnly="true" FieldLabel="Evento" runat="server" MaxLength="255" />
                                                    </ext:Anchor>
                                                </ext:FormLayout>
                                            </Body>
                                        </ext:Panel>
                                    </ext:LayoutColumn>
                                </ext:ColumnLayout>
                            </Body>
                        </ext:FormPanel>
                    </North>
                    <Center>
                        <ext:GridPanel ID="reportPresenceGridPanel" 
                            runat="server"
                            StoreID="reportPresenceStore"
                            Collapsible="true"  
                            AutoExpandColumn="tmconfirm" 
                            Title="Plants" 
                            Frame="true"
                            >
                            <TopBar>
                                <ext:Toolbar ID="Toolbar1" runat="server">
                                    <Items>
                                        <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                                        <ext:Button ID="Button3" runat="server" Text="Excel" Icon="PageExcel">
                                            <Listeners>
                                                <Click Handler="submitValue(#{reportPresenceGridPanel}, #{FormatType}, 'xls');" />
                                            </Listeners>
                                        </ext:Button>
                                    </Items>
                                </ext:Toolbar>
                            </TopBar>
                            
                            <ColumnModel ID="ColumnModel1" runat="server">
                                <Columns>
                                    <ext:Column ColumnID="tmconfirm" Header="Confirmação" Width="75" DataIndex="TMCONFIRM" Sortable="true" />
                                    <ext:Column ColumnID="nmuser" Header="Promoter" Width="200" DataIndex="NMUSER" Sortable="true" />
                                    <ext:Column ColumnID="nmguest" Header="Convidado" Width="200" DataIndex="NMGUEST" Sortable="true" />
                                    <ext:Column ColumnID="nmmailguest" Header="Email" Width="200" DataIndex="NMMAILGUEST" Sortable="true" />
                                    <ext:Column ColumnID="fgtypeinvite" Header="Tipo de Convite" Width="200" DataIndex="FGTYPEINVITE" Sortable="true" />
                                    <ext:Column ColumnID="nmevent" Header="Nome do Evento" Width="200" DataIndex="NMEVENT" Sortable="true" />
                                </Columns>
                            </ColumnModel>
                            <LoadMask ShowMask="true" />
                            <BottomBar>
                                <ext:PagingToolBar ID="PagingToolBar" runat="server" PageSize="5000" StoreID="reportPresenceStore" />
                            </BottomBar>
                            <View>
                <ext:GroupingView  
                    ID="GroupingView1"
                    HideGroupedColumn="true"
                    runat="server" 
                    ForceFit="true"
                    StartCollapsed="true"
                    GroupTextTpl='<span id="ColorCode-{[values.rs[0].data.TMCONFIRM]}"></span>{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
                    EnableRowBody="true">
                </ext:GroupingView>
            </View>
                            
                        </ext:GridPanel>
                    </Center>
                </ext:BorderLayout>
            </Body>
        </ext:Panel>
    </Body>
</ext:DesktopWindow>
